import config from '@/config/config.js';
import http from '@/api/http.js'

let workstationRequest={
    loadWorkstations(workstation,page=1,limit=10,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.mdBaseUrl + "/workstation/list?page="+page + "&limit=" + limit;
            if(workstation){
                if(workstation.workstationCode){
                    url += "&workstationCode=" + workstation.workstationCode;
                }
                if(workstation.workstationName){
                    url += "&workstationName=" + workstation.workstationName;
                }
                if (workstation.workShopId){
                    url += "&workShopId=" + workstation.workShopId;
                }
                if (workstation.processId){
                    url += "&processId=" + workstation.processId;
                }
            }
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    }, save(workstation,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.mdBaseUrl + "/workstation/save";
            http.post(url,workstation,callBack);
        }else{
            callBack(undefined);
        }
    }, updateWorkstationById(workstation,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workstation/update";
            http.put(url,workstation,callBack);
        } else {
            callBack(undefined);
        }
    }, selectById(workstationId,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workstation/selectById?workstationId=" + workstationId;
            http.get(url,callBack);
        } else {
            callBack(undefined);
        }
    }
    , deleteWorkstationById(workstationId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workstation/delete?workstationId=" + workstationId;
            http.delete(url,callBack);
        } else {
            callBack(undefined);
        }
    }, deleteWorkstations(workstationIds,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workstation/deletes?a=1";
            if(workstationIds){
                workstationIds.forEach(id=> url += '&workstationId='+id);
            }
            http.delete(url,callBack);
        } else {
            callBack(undefined);
        }
    }, ListWorkstations(callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workstation/ListWorkstations";
            http.get(url,callBack);
        } else {
            callBack(undefined);
        }
    }
}

export default workstationRequest;